import api from '@/api';

export default {
  namespace: 'currency',

  state: {
    currencyList: [],
  },

  effects: {
    *queryCurrencies({ payload }, { call }) {
      return yield call(api.base.queryCurrencies, payload)
    },
    *fetch(_, { call, put }) {
      const response = yield call(api.base.queryCurrencies);
      if (response.errorCode === 0) {
        yield put({
          type: 'save',
          payload: response.data,
        });
      }
    },
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        currencyList: payload
      };
    },
  },
};
